﻿<div class="form-horizontal" ms-controller="CRM">
    <div style="margin: 0 80px;">
        <div>
            <!--<div class="fg-item"><span>基本信息</span></div>-->
            <ul class="clearfix" style="display: block;padding:0">
                <li class="add-item add-width fl-left">
                    <label class="add-item-label"><i>*</i>姓名</label>
                    <div class="add-ic">
                        <input type="text" autofocus="autofocus" ms-duplex="modelData.UserXM" class="form-control szhl_require" />
                    </div>
                </li>
                <li class="add-item add-width fl-right">
                    <label class="add-item-label">对应客户</label>
                    <div class="add-ic">

                        <div class="input-group " style="width:100%">
                            <input type="text" class="form-control szhl_select ">
                            <span class="input-group-addon" ms-if="modelData.KHID" ms-click="ClearKH()"><i class="iconfont icon-shanchu ft14 " style="color:white"></i></span>
                        </div>
                    </div>
                </li>
                <li class="add-item add-width fl-left">
                    <label class="add-item-label"><i>*</i>手机</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.TelePhone" class="form-control szhl_require szhl_Int" />
                    </div>
                </li>
                <li class="add-item add-width fl-right">
                    <label class="add-item-label">QQ</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.QQ" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-left">
                    <label class="add-item-label">电话</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.MobilePhone" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-right">
                    <label class="add-item-label">职务</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Position" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-widthall">
                    <label class="add-item-label">地址</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Address" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-widthall">
                    <label class="add-item-label">备注</label>
                    <div class="add-ic">
                        <textarea ms-duplex="modelData.Remark" rows="3" class="span2 form-control "></textarea>
                    </div>
                </li>
            </ul>
        </div>
        <div class="extdiv"></div>
        <div>
            <div class="fg-item"><span>详细信息</span><i id="btnOtherInfo"></i></div>
            <ul class="clearfix" style="padding:0" id="OtherInfo">
                <li class="add-item add-width fl-left">
                    <label class="add-item-label">分机</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Extension" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-right ">
                    <label class="add-item-label">传真</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.FixNo" class="form-control" />
                    </div>
                </li>
                <!--<li class="add-item add-width fl-right ">
                    <label class="add-item-label">公司</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Company" class="form-control" />
                    </div>
                </li>-->
                <li class="add-item add-width fl-left">
                    <label class="add-item-label">部门</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Department" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-right ">
                    <label class="add-item-label">邮箱</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.EMail" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-left">
                    <label class="add-item-label">性别</label>
                    <div class="add-ic">
                        <select name="conType" ms-duplex="modelData.UserSex" class="form-control">
                            <option value="">请选择性别</option>
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>
                    </div>
                </li>

                <li class="add-item add-width fl-right ">
                    <label class="add-item-label">微信</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Weixin" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-left">
                    <label class="add-item-label">网址</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.WebSite" class="form-control" />
                    </div>
                </li>
                <li class="add-item add-width fl-right ">
                    <label class="add-item-label">生日</label>
                    <div class="add-ic">
                        <input id="conNR" type="text" ms-duplex="modelData.Birthday" class="szhl_form_date null form-control" />
                    </div>
                </li>
                <li class="add-item add-widthall">
                    <label class="add-item-label">邮编</label>
                    <div class="add-ic">
                        <input id="conNR" type="text" ms-duplex="modelData.PostCode" class="form-control" />
                    </div>
                </li>                
                <!--<li class="add-item add-width fl-left">
                    <label class="add-item-label">学历</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Education" class="form-control" />
                    </div>
                </li>-->
                <li class="add-item add-widthall">
                    <label class="add-item-label">附件</label>
                    <div class="add-ic">
                        <input type="text" ms-duplex="modelData.Files" class="span2 form-control szhl_Upload" />
                    </div>
                </li>
            </ul>
        </div>
    </div>
</div>

<script>
    var tempmodel = avalon.define({
        $id: "CRM",
        ColumnData: [],
        name: "客户联系人管理",
        iswf: false,//是否属于流程表单
        khid: ComFunJS.getQueryString("khid"),
        inittemp: function (strId) {
            
            if (strId) {
                //编辑加载数据
                $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETKHLXRMODEL', { P1: strId }, function (resultData) {
                        tempmodel.modelData = resultData.Result;
                        if (tempmodel.modelData.Birthday && tempmodel.modelData.Birthday.length > 10) {
                            tempmodel.modelData.Birthday = tempmodel.modelData.Birthday.substring(0, 10);
                        }
                        $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETALLKH', {}, function (resultData) {
                                tempmodel.ColumnData = resultData.Result;

                                tempmodel.kh();
                        })

                        setTimeout("ComFunJS.initForm()", 500);
                })
            } else {
                $.getJSON('/API/VIEWAPI.ashx?Action=CRM_GETALLKH', {}, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        tempmodel.ColumnData = resultData.Result;
                        if (tempmodel.khid) {
                            tempmodel.modelData.KHID = tempmodel.khid;
                        }
                        tempmodel.kh();
                    }
                })
                pmodel.isDraft = true;
                ComFunJS.initForm();
                //$(".btnSucc").text("送审");
            }
        },//初始化
        modelData: { "KHID": "", "UserXM": "", "UserSex": "", "TelePhone": "", "Department": "", "Position": "", "EMail": "", "QQ": "", "Weixin": "", "Address": "", "Remark": "", "Files": "", "WebSite": "", "PostCode": "", "Birthday": "", "Extension": "", "FixNo": "", "Education": "", "Company": "", "Mailbox": "", "Others": "" },
        SaveData: function (callback) {
            $.post("/API/VIEWAPI.ashx?ACTION=CRM_ADDKHLXR", { P1: JSON.stringify(tempmodel.modelData.$model) }, function (result) {
                return callback.call(this, result);
            });
        }, kh: function () {
            tempmodel.ColumnData.forEach(function (item) {
                if (item.ID == tempmodel.modelData.KHID) {
                    $(".szhl_select").val(item.KHName);
                }
            })
            if ($(".szhl_select").length > 0) {
                var tabsel = $(".szhl_select").YanSelect({
                    valueindex: 0,//值对应列
                    textindex: 1,
                    dataobj: tempmodel.ColumnData,
                    columns: [{ "fieldname": "ID", "text": "序号" }, { "fieldname": "KHName", "text": "客户名称" }],
                    afterSelect: function (dom) {
                        tempmodel.modelData.KHID = dom.attr('dataid')
                    },
                    eventadd: function (val) {
                        if (val) {
                            $.getJSON('/API/VIEWAPI.ashx?Action=CRM_ADDKHBYNAME', { P1: val }, function (resultData) {
                                    tabsel.extaddrow(resultData.Result)
                            })
                        }
                    }
                });
            }
        },
        ClearKH: function () {
            $(".szhl_select").val("");
            tempmodel.modelData.KHID = "";
        }
    });

</script>